//
//  THShareBaseWebViewController.m
//  LMWebViewDemo
//
//  Created by 卢蒙蒙 on 16/05/16.
//  Copyright (c) 2015年 TaiHe. All rights reserved.
//

#import "LMShareBaseWebViewController.h"
#import "LMShareView.h"
#import "SVProgressHUD.h"


@interface LMShareBaseWebViewController ()

@end


@implementation LMShareBaseWebViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 添加右侧的分享按钮
    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    shareButton.frame = CGRectMake(0, 0, 60, 40);
    shareButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [shareButton setTitleColor:[UIColor colorWithRed:52.0/255 green:52.0/255 blue:52.0/255 alpha:1] forState:UIControlStateNormal];
    shareButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [shareButton addTarget:self action:@selector(rigthButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [shareButton setImage:[UIImage imageNamed:@"trMore"] forState:UIControlStateNormal];
    
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:shareButton];
    self.navigationItem.rightBarButtonItem = item;
    
}



- (void)rigthButtonPressed {
    
    // 为降低耦合度，改为使用通知发送
    NSString *shareTitle = self.shareModel.title;
    NSString *shareContent = self.shareModel.content;
    NSString *shareUrl = self.shareModel.contentUrl;
    
    if (shareTitle.length == 0) {
        shareTitle = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    }
    
    
    if (shareContent == 0) {
        shareContent = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];;
    }
    
    
    LMShareView *shareView =  [[LMShareView alloc] initWithImageNameArray:nil titleArray:nil clickAtIndex:^(NSUInteger index) {
        
        switch (index) {
                //微信
            case 0:
                
                //[THShareApi shareToWechatSessionWithshareTitle:shareTitle shareText:shareContent shareUrl:shareUrl shareImage:nil inController:controller];
                
                break;
                
            case 1:
                //好友圈
                
                //[THShareApi shareToWechatTimelineWithshareTitle:shareTitle shareText:shareContent shareUrl:shareUrl shareImage:nil inController:controller];
                break;
                
            case 2:
                //微博
                //[THShareApi shareToSinaWithshareTitle:shareTitle shareText:shareContent shareUrl:shareUrl shareImage:nil inController:controller];
                
                
                break;
                
            case 3:
                //qq
                //[THShareApi shareToQQWithshareTitle:shareTitle shareText:shareContent shareUrl:shareUrl shareImage:nil inController:controller];
                
                break;
                
            case 4:
                // qq 空间
                
                //[THShareApi shareTOQzoneWithshareTitle:shareTitle shareText:shareContent shareUrl:shareUrl shareImage:nil inController:controller];
                
                break;
                
            case 5:
                //复制
            {
                if (!shareContent) {
                    
                    [SVProgressHUD showErrorWithStatus:@"复制失败，请稍候重试"];
                    return ;
                }
                UIPasteboard *paste = [UIPasteboard generalPasteboard];
                paste.string =shareUrl;
                [SVProgressHUD showSuccessWithStatus:@"复制成功"];
            }
                break;
                
            default:
                break;
        }
        
    }];
    
    [shareView show];


}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
